//
// App delegate
//

#import <Cocoa/Cocoa.h>

#import <queue>


class RtMidiOut;

enum MantaState
{
    STATE_QUIT,
    STATE_DISCONNECTED,
    STATE_CONNECTING,
    STATE_CONNECTED
};

enum PressureState
{
    PRESSURE_OFF,
    PRESSURE_POLYPHONIC,
    PRESSURE_CHANNEL,
};

@interface AppDelegate : NSObject
{
    NSStatusItem*   _statusItem;
    NSMenuItem*     _connectItem;
    NSMenuItem*     _mantaItem;
    NSMenuItem*     _layoutItem[6];
    NSMenuItem*     _baseItem[12];
    NSMenuItem*     _pressOffItem;
    NSMenuItem*     _pressAfterItem;
    NSMenuItem*     _pressCCItem;
    MantaState      _state;
    RtMidiOut*      _midi;
    int             _layout_index;
    int             _base_index;
    int             _slider_val[2];
    int             _button_val[4];
    double          _pad_time[48];
    int             _pad_val[48];
    int             _pad_note[48];
    int             _pad_cc;
    int             _pad_max;
    unsigned char   _index_to_pitch[48];
    PressureState   _pressure;
    std::queue<int>* _pending;
}

-(void) applicationDidFinishLaunching: (NSNotification*) aNotification;
-(void) applicationWillTerminate: (NSNotification*) aNotification;
-(void) awakeFromNib;

-(void) mantaThread;
-(void) setStateFrom: (MantaState) from to: (MantaState) to;

-(void) setLayout: (int) idx baseNote: (int) base;
-(void) setPressure: (PressureState) state;

-(void) onQuit;
-(void) onLayout: (NSMenuItem*) item;
-(void) onBase: (NSMenuItem*) item;
-(void) onPressureOff;
-(void) onPressureAftertouch;
-(void) onPressureCC;
-(void) onConnect;
-(void) onConnected: (NSNumber*) serial_num;
-(void) onDisconnected;
-(void) onPadEvent: (int) idx withValue: (int) value;
-(void) onPadVelocityEvent: (int) idx withVelocity: (int) velocity;
-(void) onSliderEvent: (int) idx withValue: (int) value;
-(void) onButtonEvent: (int) idx withValue: (int) value;

@end

